package org.example.leetCode;


import java.util.Arrays;

public class plusOne {
    public static void main(String[] args) {
        int[] d = {9, 9, 9};
        d = plusOne1(d);
        System.out.println(Arrays.toString(d));
    }

    public static int[] plusOne1(int[] digits) {
        int i = digits.length - 1;
        digits[i]++;
        while (digits[i] == 10) {
            digits[i] = 0;
            if (i == 0) {
                int[] res = new int[digits.length + 1];
                res[0] = 1;
                return res;
            }
            i--;
            digits[i]++;

        }
        return digits;
    }
}
